package database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Medicine {
	
	private int medID;
	private String medName;
	private String medDesc;
	private String indications;
	private String typeDosage;
	private double maxDosage;
	
	private ArrayList medicines;
	Connection con;
	
	public Medicine(){
		
	}
	
	public Medicine(int medID, String medName, String medDesc, String indications, String typeDosage, double maxDosage){
		this.medID = medID;
		this.medName = medName;
		this.medDesc = medDesc;
		this.indications = indications;
		this.typeDosage = typeDosage;
		this.maxDosage = maxDosage;
	}
	
	
	public int getMedID() {
		return medID;
	}
	
	public void setMedID(int medID) {
		this.medID = medID;
	}
	
	public String getMedName() {
		return medName;
	}
	
	public void setMedName(String medName) {
		this.medName = medName;
	}
	
	public String getMedDesc() {
		return medDesc;
	}
	
	public void setMedDesc(String medDesc) {
		this.medDesc = medDesc;
	}
	
	public String getIndications() {
		return indications;
	}
	
	public void setIndications(String indications) {
		this.indications = indications;
	}
	
	public String getTypeDosage() {
		return typeDosage;
	}
	
	public void setTypeDosage(String typeDosage) {
		this.typeDosage = typeDosage;
	}
	
	public double getMaxDosage() {
		return maxDosage;
	}
	
	public void setMaxDosage(double maxDosage) {
		this.maxDosage = maxDosage;
	}
	
	public List getMedicine() throws SQLException {
		medicines = new ArrayList();

		try {
			String selectStatement = "SELECT * FROM medicine";
			PreparedStatement prepStmt = con.prepareStatement(selectStatement);
			ResultSet rs = prepStmt.executeQuery();

			while (rs.next()) {
				Medicine bd = new Medicine(rs.getInt(1),
						rs.getString(2), rs.getString(3), rs.getString(4),
						rs.getString(5), rs.getDouble(6));

				if (rs.getInt(9) > 0) {
					medicines.add(bd);
				}
			}

			prepStmt.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
			throw ex;
		}
		return medicines;
	}

}
